#include <iostream>
#include <vector>
#include "Thread.hpp"

using namespace ThreadModule;

void print(int &cnt)
{
    std::cout << "hello I am myself thread, cnt: " << cnt-- << std::endl;
    sleep(1);
}

const int num = 10;
int a = 10;
int main()
{
    std::vector<Thread<int> > threads;
    // 1. 创建一批线程
    for (int i = 0; i < num; i++)
    {
        std::string name = "thread-" + std::to_string(i + 1);
        threads.emplace_back(print, a, name);
        sleep(1);
    }

    // 2. 启动 一批线程
    for (auto &thread : threads)
    {
        thread.Start();
    }

    // 3. 等待一批线程
    for (auto &thread : threads)
    {
        thread.Join();
        std::cout << "wait thread done, thread is: " << thread.name() << std::endl;
    }

    return 0;
}




// void print(int &cnt)
// {
//     std::cout << "hello I am myself thread, cnt: " << cnt-- << std::endl;
//     sleep(1);
// }

// int main()
// {
//     Thread<int> t1(print, 10);
//     t1.Start();
//     std::cout << "name: "<< t1.name() << std::endl;

//     t1.Join();
//     return 0;
// }

